﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Practices.Unity;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using SharedGenomics.Annotations;
using SharedGenomics.Workbench.Annotations;
using SharedGenomics.Workbench.Annotations.Requests;
using SharedGenomics.Workbench.Tests.TestObjects;

namespace SharedGenomics.Workbench.Tests.Annotations.Requests
{
    [TestClass]
    public class AnnotationRequestTests
    {
        private AnnotationRequestBuilderFactory builderFactory;
        private TestAnnotationRequestStage postStage;

        [TestInitialize]
        public void FixtureSetup()
        {
            var graphProvider = new AnnotationKeyDependencyGraphProvider();
            var repMediator = new AnnotationRepositoryMediator(graphProvider);

            repMediator.Add(AnnotationKey.SnpName, "rs001", null);

            UnityContainer container = new UnityContainer();
            this.builderFactory = new AnnotationRequestBuilderFactory(container);
            this.postStage = new TestAnnotationRequestStage();
        }

        [TestMethod]
        public void ShouldCreateGoogleSearchRequest()
        {
            var requestStage = this.builderFactory.GetRequestStageFor(AnnotationKey.GoogleSearch);
            var context = new AnnotationRequestContext(AnnotationKey.GoogleSearch, "rs001");

            var stages = new[] { this.postStage }.Cast<IAnnotationRequestStage>().ToList();
            var travStrat = new AnnotationRequestPipelineTraversalStrategy(stages);
            requestStage.Process(context, travStrat);

            Assert.IsInstanceOfType(context.OutputArtifacts.First().Value, typeof(GoogleSearchAnnotation));
        }
    }
}
